#coding=utf-8
import unittest
from selenium import webdriver
from appium import webdriver
from time import sleep
from nav_plugin_op import nav_plugin_factory
from selenium.common.exceptions import WebDriverException
import os
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from selenium.webdriver.support.ui import WebDriverWait
from Public import BaseConstant

#实例化基础参数
navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
basicAction = BasicAction()
Sepcial_inspect_Paramter_instances = BaseConstant.Sepcial_inspect_Paramter
# nav_name = "工作"
# plugin_name = "专项普查"
nav_name = ["导航栏工作",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-专项普查",'name','专项普查']
opinin_keys_name = "处理"

class special_inspect_factory():

	def open_inspect_plug(self,driver,file_path):

		try:
            # 点击工作的导航，打开工作列表
			element_oprate_instance.element_click(nav_name,file_path)
            # 点击"专项普查"的插件，打开插件
			element_oprate_instance.element_click(plugin_name,file_path)
            #等待专项普查页面内容进行加载，加载完成之后进行页面确认并界面

			if element_oprate_instance.element_display_commit(Sepcial_inspect_Paramter_instances.inspect_name, file_path):
				element_oprate_instance.element_save_pic(file_path, 'open_Inspect_plug_successful')
			else:
				print 'test failed'
			

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_Inspect_plug_fail')
			raise


	def Census_Report(self,driver,file_path):

		try:
			driver.implicitly_wait(15)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.task_xpath, file_path)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.census_report_name, file_path)
			sleep(5)
			# driver.find_element_by_id(type_id).click()
			# driver.find_element_by_name(type_keys_name.decode("utf-8")).click()
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.report_location_id, file_path)
			sleep(3)
			driver.swipe(400,250,400,50,800)
			sleep(1)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.map_bottom_id, file_path)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.confirm_name, file_path)
			sleep(1)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.opinin_name, file_path)
			element_oprate_instance.element_send_keys(Sepcial_inspect_Paramter_instances.opinin_name, opinin_keys_name.decode("utf-8"), file_path)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.add_photo_id, file_path)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.tool_photoadd_id, file_path)
			sleep(1)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.select_photo_xapth, file_path)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.confirm_id, file_path)
			#tijiao
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.report_btn_id, file_path)

			element_oprate_instance.element_save_pic(file_path, 'Census_Report_successful')

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'Census_Report_fail')
			raise

	def scan_census_history(self,driver,file_path):

		try:
			#查看普查记录
			#点击已经结束
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.finish_name, file_path)
			sleep(3)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.task_xpath, file_path)
			sleep(1)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.census_history_name, file_path)
			sleep(2)
			element_oprate_instance.element_save_pic(file_path, 'scan_census_history_successful')
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.census_history_name, file_path)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.exit_id, file_path)
			element_oprate_instance.element_click(Sepcial_inspect_Paramter_instances.exit_id, file_path)

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'scan_census_history_fail')
			raise

if __name__ == '__main__':
	unittest.main()
